`
https://leetcode.cn/problems/rotate-array/
`

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var rotate = function (nums, k) {
  const n = nums.length
  k = k % n

  // 反转整个数组
  reverse(nums, 0, n - 1)
  // 反转前 k 个元素
  reverse(nums, 0, k - 1)
  // 反转剩余的元素
  reverse(nums, k, n - 1)
};

function reverse(nums, start, end) {
  while (start < end) {
    const temp = nums[start];
    nums[start] = nums[end];
    nums[end] = temp;
    start++;
    end--;
  }
}